<?php
class Survey extends AppModel {
	var $name = 'Survey';
	
	var $hasOne = 'SurveyType';
	
	var $hasAndBelongsToMany = array(
        'Question' =>
            array(
	            'className'              => 'Question',
	            'joinTable'              => 'questions_surveys',
	            'foreignKey'             => 'survey_id',
                'associationForeignKey'  => 'question_id',
                'unique'                 => true,
                'conditions'             => '',
                'fields'                 => '',
                'order'                  => '',
                'limit'                  => '',
                'offset'                 => '',
                'finderQuery'            => '',
                'deleteQuery'            => '',
                'insertQuery'            => ''
            ),
		'User' =>
			array(
				'className'				=> 'User',
				'joinTable'				=> 'surveys_users',
				'foreignKey'			=> 'survey_id',
				'associationForeignKey' => 'user_id',
				'unique'				=> 'true',
				'conditions'             => '',
                'fields'                 => '',
                'order'                  => '',
                'limit'                  => '',
                'offset'                 => '',
                'finderQuery'            => '',
                'deleteQuery'            => '',
                'insertQuery'            => ''
			),
		'Audiencelist' =>
			array(
				'className'				=> 'Audiencelist',
				'joinTable'				=> 'audiencelists_surveys',
				'foreignKey'			=> 'survey_id',
				'associationForeignKey' => 'audiencelist_id',
				'unique'				=> 'true',
				'conditions'             => '',
                'fields'                 => '',
                'order'                  => '',
                'limit'                  => '',
                'offset'                 => '',
                'finderQuery'            => '',
                'deleteQuery'            => '',
                'insertQuery'            => ''
			)
	);
	
	var $isDeleted = 0;
	
	var $validate = array(
		'name' => array(
			'rule' => 'notEmpty',
			'message' => 'Please enter a survey name'
		),
	);

	var $actsAs = array('Uuid' => array('field' => 'uuid'), 'ExtendAssociations', 'Containable'); 
	
	function availableSurveys(){
		$conditions = array('Survey.isDeleted' => '0');
		$retVal = $this->findAll( $conditions, null);
		//pr($retVal);
		return $retVal;
	}
}
?>